import cv2
import matplotlib.pyplot as plt
import numpy as np
import math

def myfilter(img,kernel):
    h=img.shape[0]
    w=img.shape[1]
    img1=np.zeros((h,w),np.int8)
    for i in range (1,h-1):
        for j in range (1,w-1):
            sum=0
            for k in range(-1,2):
                for I in range(-1,2):
                    sum+=img[i+k,j+I]*kernel[k+1,I+1]
            img1[i,j]=sum
    return img1

img=np.array([[1,0,0,0,0,1],
              [0,1,0,0,1,0],
              [0,0,1,1,0,0],
              [1,0,0,0,1,0],
              [0,1,0,0,1,0],
              [0,0,1,0,1,0]])
kernel=np.array([[1,-1,-1],
                 [-1,1,-1],
                 [-1,-1,1]])
filtered_img1=myfilter(img,kernel)                                           
print (filtered_img1)